<template>
	<!--公司信息	-->
	<div>
		<FormPanel ref="FormPanel" :list="initForm" :cols="2" :formType="formType" :labelWidth="180" :isSubmitBtn="false" @formChange="formChangeHandle" class="mtop" />
	</div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import * as types from '@/api/cms-api/origin/originInfo/types';

import vm from './bridge';

export default {
	mixins: [dictionary],
	model: {
		prop: 'pdata',
		event: 'click'
	},
	props: {
		pdata: {
			type: Object,
			default: () => ({})
		},
		formType: {
			type: String,
			required: true
		},
		formOptions: {
			type: Object,
			required: true
		}
	},
	data() {
		return {
			initForm: this.initFormFun()
		};
	},
	mounted() {
		//注册经销商类型变化时触发的事件
		//在审核时，给此页面的类型为只读，但是基本信息（infoBase可以编辑，会显示会触发事件，事件会触发禁用取消，覆盖整个表单的类型（表单类型为show，但是依旧可以输入，（部分）））
		if (this.formType != 'show') {
			vm.$on('changeDealerType', this.changeDealerType);
		}
	},
	methods: {
		//初始化数据
		init(data) {
			this.initForm.forEach(x => {
				if (this.pdata[x.fieldName]) {
					x.initialValue = this.pdata[x.fieldName];
				}
			});
		},
		//初始化数据（带触发事件，为经销商提报添加的）
		initPre(data) {
			if (this.formType != 'show') {
				if (!this.pdata.companyName) {
					this.pdata.companyName = this.pdata.dealerName;
				}
				// vm.$emit('changeDealerType', this.pdata);
				vm.$emit('changeDealerType', this.pdata.dealerType);
				// this.supplementChangeDealerType(this.pdata.dealerType);
			}
			this.initForm.forEach(x => {
				if (this.pdata[x.fieldName]) {
					x.initialValue = this.pdata[x.fieldName];
				}
			});
		},
		//表单验证通过后
		formChangeHandle(val) {
			this.pdata = Object.assign(this.pdata, val);
			//传递数据到父组件里
			this.$emit('click', this.pdata);
			//触发外部的事件，以标志着本表单已经准备完毕
			this.$emit('formchange', this.pdata);
		},
		//开放的提交方法
		saveDialog() {
			this.$refs.FormPanel.SUBMIT_FORM();
		},
		//经销商类型变更时
		changeDealerType(value) {
			console.log("经销商类型变更时 =>",value)
			//判断是否是dle页面，是则使用dlr专用验证
			let suffix = this.formOptions.formType === types.DEALER_INFO_FORM_STATUS_SUBMISSION_DLR ? 'DLR' : '';
			//根据类型处理验证
			if (types.DEALER_INFO_DEALER_TYPE_4S === value) {
				//4S
				vm.changeForm(this.initForm, '4S' + suffix, false);
				vm.clearValidate(this.$refs.FormPanel);
			} else if (types.DEALER_INFO_DEALER_TYPE_SINGLE_AFTER_SALE === value) {
				//单一售后
				vm.changeForm(this.initForm, 'SH' + suffix, false);
				vm.clearValidate(this.$refs.FormPanel);
			} else if (types.DEALER_INFO_DEALER_TYPE_SINGLE_SALE === value) {
				//单一销售
				vm.changeForm(this.initForm, 'XS' + suffix, false);
				vm.clearValidate(this.$refs.FormPanel);
			} else if (types.DEALER_INFO_DEALER_TYPE_DIRECT_SHOP === value) {
				//SPACE
				vm.changeForm(this.initForm, 'SPACE' + suffix, false);
				vm.clearValidate(this.$refs.FormPanel);
			} else if (types.DEALER_INFO_DEALER_TYPE_NO_DIRECT_SHOP === value) {
				//RACE
				vm.changeForm(this.initForm, 'RACE' + suffix, false);
				vm.clearValidate(this.$refs.FormPanel);
			} else if (types.DEALER_INFO_DEALER_TYPE_BIG_CUSTOMER === value) {
				//大客户
				vm.changeForm(this.initForm, 'DKH' + suffix, false);
				vm.clearValidate(this.$refs.FormPanel);
			}
			//this.supplementChangeDealerType(value);
		},
		//补充验证
		supplementChangeDealerType(value) {
			if (this.formOptions.formType === types.DEALER_INFO_FORM_STATUS_SUBMISSION_DLR) {
				//单一售后、RACE、SPACE店首笔提车款附件不必填
				if (types.DEALER_INFO_DEALER_TYPE_SINGLE_AFTER_SALE === value || types.DEALER_INFO_DEALER_TYPE_DIRECT_SHOP === value || types.DEALER_INFO_DEALER_TYPE_NO_DIRECT_SHOP === value) {
					//首笔提车款附件
					this.initForm.find(x => x.fieldName === 'firstPaymentEnclosureList').rules = [];
					//4S店和单一销售必填
				} else if (types.DEALER_INFO_DEALER_TYPE_4S === value || types.DEALER_INFO_DEALER_TYPE_SINGLE_SALE === value) {
					this.initForm.find(x => x.fieldName === 'firstPaymentEnclosureList').rules = [{ required: true, message: '必填', trigger: 'blur' }];
				} else {
					this.initForm.find(x => x.fieldName === 'firstPaymentEnclosureList').rules = [];
				}
			}
		},
		//表单数据
		initFormFun() {
			let bt = { required: true, message: '必填', trigger: ['change', 'blur'] };
			let btl = [bt];
			let sj = { pattern: /^1[2-9]\d{9}$/, message: '请填写正确的手机号', trigger: ['change', 'blur'] };
			let email = { type: 'email', message: '请输入正确的邮箱', trigger: 'blur' };
			let jy = {disabled:true};
			let yc = {hidden:true};
			return [
				{
					type: 'INPUT',
					label: '公司名称',
					fieldName: 'companyName',
					initialValue: '',
					maxlength: 300,
					rules: btl,
					rules4S: [], //4S店
					rulesSH: [], //单一售后
					rulesXS: [], //单一销售
					rulesSPACE: [], //SPACE
					rulesRACE: [], //RACE
					rulesDKH: [], //大客户

					rules4SDLR: jy, //4S店(dlr)
					rulesSHDLR: jy, //单一售后(dlr)
					rulesXSDLR: jy, //单一销售(dlr)
					rulesSPACEDLR: jy, //SPACE(dlr)
					rulesRACEDLR: jy, //RACE(dlr)
					rulesDKHDLR: jy //大客户(dlr)
				},
				{
					type: 'INPUT',
					label: '法定代表人',
					fieldName: 'representative',
					initialValue: '',
					maxlength: 30,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{
					type: 'INPUT',
					label: '销售热线',
					fieldName: 'salesLine',
					initialValue: '',
					placeholder: '请输入',
					maxlength: 30,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: jy,
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: btl,
					rulesSHDLR: btl,
					rulesXSDLR: jy,
					rulesSPACEDLR: btl,
					rulesRACEDLR: btl,
					rulesDKHDLR: btl
				},
				{
					type: 'INPUT',
					label: '销售邮箱',
					fieldName: 'salesEmail',
					initialValue: '',
					placeholder: '请输入',
					maxlength: 60,
					rules: [bt, email],
					rules4S: [email],
					rulesSH: [email],
					rulesXS: jy,
					rulesSPACE: [email],
					rulesRACE: [email],
					rulesDKH: [email],

					rules4SDLR: [bt, email],
					rulesSHDLR: [bt, email],
					rulesXSDLR: jy,
					rulesSPACEDLR: [bt, email],
					rulesRACEDLR: [bt, email],
					rulesDKHDLR: [bt, email]
				},
				{
					type: 'INPUT',
					label: '售后服务热线',
					fieldName: 'serviceLine',
					initialValue: '',
					placeholder: '请输入',
					maxlength: 30,
					rules: btl,
					rules4S: [],
					rulesSH: jy,
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: btl,
					rulesSHDLR: jy,
					rulesXSDLR: btl,
					rulesSPACEDLR: btl,
					rulesRACEDLR: btl,
					rulesDKHDLR: []
				},
				{
					type: 'INPUT',
					label: '售后邮箱',
					fieldName: 'serviceEmail',
					initialValue: '',
					placeholder: '请输入',
					maxlength: 60,
					rules: [bt, email],
					rules4S: [email],
					rulesSH: jy,
					rulesXS: [email],
					rulesSPACE: [email],
					rulesRACE: [email],
					rulesDKH: [email],

					rules4SDLR: [bt, email],
					rulesSHDLR: jy,
					rulesXSDLR: [bt, email],
					rulesSPACEDLR: [bt, email],
					rulesRACEDLR: [bt, email],
					rulesDKHDLR: [email]
				},
				// {type:'INPUT',label:'前台座机',fieldName:'frontHotline',initialValue:'',placeholder:'请输入',rules:[{required:true,message:'必填',trigger:'change'}],
				// 	maxlength:30,
				// 	disabled:false},
				{
					type: 'INPUT',
					label: '24小时服务电话',
					fieldName: 'hotLine',
					initialValue: '',
					placeholder: '请输入',
					maxlength: 30,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: btl,
					rulesSHDLR: btl,
					rulesXSDLR: btl,
					rulesSPACEDLR: btl,
					rulesRACEDLR: btl,
					rulesDKHDLR: []
				},
				{
					type: 'DATE',
					label: '成立日期',
					fieldName: 'establishmentDate',
					dateType: 'date',
					valueFormat: 'yyyy-MM-dd',
					initialValue: '',
					placeholder: '请选择',
					style: { width: '100%' },
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{
					type: 'INPUT',
					label: '纳税人识别号',
					fieldName: 'taxpayerIdentityNumber',
					initialValue: '',
					maxlength: 20,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{
					type: 'INPUT',
					label: '登记机关',
					fieldName: 'registerGov',
					selfCols: 2,
					initialValue: '',
					placeholder: '请输入',
					maxlength: 300,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{
					type: 'DATE',
					label: '营业执照有效期',
					fieldName: 'businessTerm',
					valueFormat: 'yyyy-MM-dd',
					initialValue: '',
					maxlength: 100,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},

				{
					type: 'TEXT_AREA',
					label: '营业执照地址',
					fieldName: 'registerAddress',
					selfCols: 2,
					rows: 2,
					initialValue: '',
					placeholder: '请输入',
					maxlength: 240,
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},

				{type:'INPUT',label:'道路运输经营许可证',fieldName:'roadTransportationLicense',initialValue:'',placeholder:'请输入',
					maxlength:100,
					rules:btl,
					rules4S: btl,
					rulesXS: jy,
					rulesSH: btl,
					rulesSPACE: btl,
					rulesRACE: btl,
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{type:'SELECT',label:'维修资质类别',fieldName:'maintenanceCategory',placeholder:'请选择',initialValue:'',itemList:this.createDictList('2587'),
					rules4S: [],
					rulesXS: jy,
					rulesSH: btl,
					rulesSPACE: jy,
					rulesRACE: jy,
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{type: 'UPLOAD_FILE',label: '许可证附件',fieldName: 'licenceEnclosureList',initialValue: [],
					selfCols:2,
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						min:1,
						max:10240,//kb
						fileTypes:[
							'jpg','jpeg','png','gif',
							'doc','docx','xls','xlsx','ppt','pptx','txt','pdf',
							'rar','zip',
						],
					},
					rules4S: [],
					rulesXS: jy,
					rulesSH: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},

				{
					type: 'UPLOAD_FILE',
					label: '营业执照扫描件',
					selfCols: 2,
					fieldName: 'businessLicenseEnclosureList',
					initialValue: [],
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						min: 1,
						max: 10240, //kb
						fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
					},
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{
					type: 'UPLOAD_FILE',
					label: '法定代表人附件',
					selfCols: 2,
					fieldName: 'legalRepresentativeEnclosureList',
					initialValue: [],
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						min: 1,
						max: 10240, //kb
						fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
					},
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [],

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy
				},
				{
					type: 'UPLOAD_FILE',
					label: '首笔提车款附件',
					selfCols: 2,
					fieldName: 'firstPaymentEnclosureList',
					initialValue: [],
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						min: 1,
						max: 10240, //kb
						fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
					},
					rules: btl,
					rules4S: [],
					rulesSH: [],
					rulesXS: [],
					rulesSPACE: [],
					rulesRACE: [],
					rulesDKH: [], //t

					rules4SDLR: jy,
					rulesSHDLR: jy,
					rulesXSDLR: jy,
					rulesSPACEDLR: jy,
					rulesRACEDLR: jy,
					rulesDKHDLR: jy //t
				}
			];
		}
	}
};
</script>
